﻿/// <reference name="MicrosoftAjax.js"/>

// Name:        Sagacity.debug.js
// Assembly:    Sagaciy
// Version:     1.0.0.0
// FileVersion: 1.0.2009.1
//!-----------------------------------------------------------------------
//! Copyright (C) Sagacity Corporation. All rights reserved.
//!-----------------------------------------------------------------------


window.Sg = {
///<summary>create sagacity namespace</summary>
    __namespace: true,
    __typeName: "Sg",
    getVersion: function() {return "1.0.0.0";},
    dispose:function(){},
    __upperCaseTypes: {},
    _alert:function(text){
        $get("sg_message_confirm").style.display = "none";
        $get("sg_message_ok").style.display = "";
        $get("sg_message_text").innerText = text;
        $find(sg_MessageDialogClientId).set_windowState($IG.DialogWindowState.Normal);
        sg_MessageDialogEvent = null;
    },
    alert:function(text){
        var parent = this.getTop();
        parent.Sg._alert(text);
    },
    __currentFrame:null,
    _confirm:function(text,event){
        $get("sg_message_confirm").style.display = "";
        $get("sg_message_ok").style.display = "none";
        $get("sg_message_text").innerText = text;
        $find(sg_MessageDialogClientId).set_windowState($IG.DialogWindowState.Normal);
        sg_MessageDialogEvent = event;
    },
    confirm:function(text,event){
        var parent = this.getTop();
        parent.Sg.__currentFrame = self;
        parent.Sg._confirm(text,event);
    },
    _okMessage:function(){
        if( sg_MessageDialogEvent != null)
        {
            eval("this.__currentFrame."+sg_MessageDialogEvent);
        }
        Sg._hiddenMessage();
    },
    _hiddenMessage:function(){
        $find(sg_MessageDialogClientId).set_windowState($IG.DialogWindowState.Hidden);
    },
    getTop : function(){
    	var parent = self;
	    var frmPath = "";
	    var flag = true;
	    while(flag)
	    {
		    if(parent.parent==parent)
			    flag = false;
		    else
		    {
			    parent = parent.parent;
	        }
	    }
	    return parent;
    },
    showModalDialog:function( url,afterEvent,datasource,dialogStyle){
        var parent = this.getTop();
        parent.sg_SelectDialog.currentFrame = self;
        parent.sg_SelectDialog.open(url,afterEvent,datasource,dialogStyle);
    }
    
};
Sg.xmlDocument = function Sg$xmlDocument(){
    ///<summary>create xml document</summary>
    ///<returns>return xml document</returns>
    var xmldoc = null;
    if(typeof(window.ActiveXObject) != 'undefined')
    {	
	    try
	    {
		    //xmldoc = new ActiveXObject("MSXML2.DOMDocument.5.0");
	    }
	    catch(e)
	    {
    	
	    }
	    if(xmldoc==null)
		    xmldoc = new ActiveXObject("Microsoft.XMLDOM");
    }
    else
    {
	    xmldoc = document.implementation.createDocument("", "doc", null)
    }
    return xmldoc;	
}
Sg.Controls = function Sg$Controls(){
///<summary>control namespace</summary>
}
Sg.correctPNG = function Sg$correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6. 
{ 

    var arVersion = navigator.appVersion.split("MSIE") 

    var version = parseFloat(arVersion[1]) 

    if ((version >= 5.5) && (document.body.filters)) 

    { 

       for(var j=0; j<document.images.length; j++) 

       { 

          var img = document.images[j] 

          var imgName = img.src.toUpperCase() 

          if (imgName.substring(imgName.length-3, imgName.length) == "PNG") 

          { 

             var imgID = (img.id) ? "id='" + img.id + "' " : "" 

             var imgClass = (img.className) ? "class='" + img.className + "' " : "" 

             var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' " 

             var imgStyle = "display:inline-block;" + img.style.cssText 

             if (img.align == "left") imgStyle = "float:left;" + imgStyle 

             if (img.align == "right") imgStyle = "float:right;" + imgStyle 

             if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle 

             var strNewHTML = "<span " + imgID + imgClass + imgTitle 

             + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" 

             + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" 

             + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 

             img.outerHTML = strNewHTML 

             j = j-1 

          } 

       } 

    }     

} 

//window.attachEvent("onload", Sg$correctPNG); 

/*
Sg.__rootNamespaces = [Sg];
Sg.__registeredTypes = {};

Type.registerNamespace('Sg');
Type.registerNamespace('Sg.Controls');
*/

  //将格林威治时间转化成yyyy-MM-dd格式的时间
  function toDate(num)  
  { 
      //Fri Oct 31 18:00:00 UTC+0800 2008  
      num=num+"";
      var date="";
      var month=new Array();
      month["Jan"]=1;month["Feb"]=2;month["Mar"]=3;month["Apr"]=4;month["May"]=5;month["Jun"]=6;
      month["Jul"]=7;month["Aug"]=8;month["Sep"]=9;month["Oct"]=10;month["Nov"]=11;month["Dec"]=12;
      var week=new Array();
      week["Mon"]="一";week["Tue"]="二";week["Wed"]="三";week["Thu"]="四";week["Fri"]="五";week["Sat"]="六";week["Sun"]="日";
      str=num.split(" ");
      date=str[5]+"-";
      var mouth = parseInt(month[str[1]]) >= 10 ? month[str[1]] : "0"+month[str[1]];
      var day = parseInt(str[2]) >= 10 ? str[2] : "0"+ str[2];
      date=date+mouth+"-"+day;
      //date=date+" 周"+week[str[0]];
      return date;
}

